package com.cms.recursoshumanos.facade;

import net.rim.device.api.system.RadioInfo;

import com.cms.recursoshumanos.transport.BBRequest;
import com.cms.recursoshumanos.transport.BBRequestQueue;
import com.cms.recursoshumanos.transport.HttpRequest;

public class ApnSelectorFacade implements BBRequest.Listener {

	private static String _apnurl = "http://apps.mobmedianet.com/suscriptions/getapn.php?";
	private String suffix = "";
	
	public void buscarApnInfo()
	{
		HttpRequest req = new HttpRequest();
		req.setListener(this);
		
		int index = RadioInfo.getCurrentNetworkIndex();
	
		if(index > -1){
			_apnurl += "mnc=" + RadioInfo.getMNC(index) + "&mcc=" + RadioInfo.getMCC(index) + "&id=" + RadioInfo.getNetworkId(index) + "&name=" + RadioInfo.getNetworkName(index);
			
			req.setRequestURL(_apnurl);
			BBRequestQueue.getInstance().addRequest(req);
		} 
	}

	public void requestCancelled(BBRequest request) {
		// TODO Auto-generated method stub
		
	}

	public void requestFailed(BBRequest request) {
		// TODO Auto-generated method stub
		
	}

	public void requestStarted(BBRequest request) {
		// TODO Auto-generated method stub
		
	}
	
	public String getApnSuffix(){
		return suffix;
	}

	public void requestSucceeded(BBRequest request) {
		HttpRequest httpRequest = (HttpRequest) request;
        byte[] dataBytes = httpRequest.getResponseByte();
		suffix = new String(dataBytes);
	}
	
}

